package com.zjuee.base.utils;


import org.apache.commons.lang3.StringUtils;

public class DesensitizationUtil {

    //名字脱敏
    public static String desensitizedName(String fullName){
        String name = "";
        if (StringUtils.isNotBlank(fullName)) {
            name = StringUtils.left(fullName, 1);
            return StringUtils.rightPad(name, StringUtils.length(fullName), "*");
        }
        return name;
    }

    //手机号脱敏
    public static String desensitizedPhoneNumber(String phoneNumber){
        if(StringUtils.isNotEmpty(phoneNumber)){
            phoneNumber = phoneNumber.replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2");
        }
        return phoneNumber;
    }

    //企业信用代码脱敏
    public static String desensitizedCodeNumber(String codeNumber){
        if (StringUtils.isNotBlank(codeNumber)) {
            if(codeNumber.length() > 6){
                return StringUtils.left(codeNumber, 3).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(codeNumber, 3), StringUtils.length(codeNumber), "*"), "******"));
            } else {
                return StringUtils.left(codeNumber, 2).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(codeNumber, 1), StringUtils.length(codeNumber), "*"), "******"));
            }
        }
        return codeNumber;
    }
}
